<template>
	<view class="page-content">
		<view class="mt-20 bg_fff pd-20">
			<u--form labelPosition="left" ref="form1" labelWidth="200rpx" :labelStyle="{
				paddingLeft:'30rpx',
				fontWeight: 'bold',
				color: '#333333',
				fontSize:'30rpx'
				}" :borderBottom="false">
				<u-form-item label="媒体平台" prop="subData.popu_platform_id">
					<uni-data-picker :localdata="platform" :map="{text:'name',value:'id'}" popup-title="媒体平台"
						placeholder="请选择媒体平台" v-model="subData.popu_platform_id"></uni-data-picker>
				</u-form-item>
				<u-form-item label="账户主页链接" prop="subData.homepage">
					<u--textarea placeholder="请输入账户主页链接" v-model="subData.homepage" maxlength="-1"></u--textarea>
				</u-form-item>
				<u-form-item label="账号ID" prop="subData.acc_id">
					<u--input v-model="subData.acc_id" placeholder="请输入账号ID"></u--input>
				</u-form-item>
				<u-form-item label="账号名称" prop="subData.nickname">
					<u--input v-model="subData.nickname" placeholder="请输入账号名称"></u--input>
				</u-form-item>
				<u-form-item label="粉丝量" prop="subData.fans_num">
					<u--input v-model="subData.fans_num" placeholder="请输入粉丝量" type="number"></u--input>
				</u-form-item>
				<!-- <u-form-item label="账户品类" prop="subData.category_id">
					<uni-data-picker :localdata="category" :map="{text:'name',value:'id'}" popup-title="账户品类"
						placeholder="请选择账户品类" v-model="subData.category_id"></uni-data-picker>
				</u-form-item> -->
				<u-form-item label="启用状态" prop="subData.status">
					<!-- <uni-data-picker :localdata="status" :map="{text:'name',value:'id'}" popup-title="启用状态"
						placeholder="请选择启用状态" v-model="subData.status"></uni-data-picker> -->
					<u-switch v-model="subData.status" @change="change" :activeValue="1" :inactiveValue="0"></u-switch>
				</u-form-item>
			</u--form>
		</view>

		<view class="position_bottom" style="height: 280rpx;">
			<view class="btmBox c_ffffff" style="height: 80rpx;" @click="$u.throttle(doSub, 3000)">
				保存
			</view>

			<view class="btmBox c_ffffff mt-20" v-if="subData.id"
				style="height: 80rpx;background: none;background-color: #ccc !important;"
				@click="$u.throttle(del, 3000)">
				删除
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getSearchData,
		getAccount,
		postAccount,
		accountDel
	} from '@/config/api.js'

	export default {
		data() {
			return {
				subData: {
					id: "",
					popu_platform_id: "",
					homepage: "",
					acc_id: "",
					nickname: "",
					fans_num: "",
					category_id: "",
					status: ""
				},
				platform: [],
				category: [],
				status: [],
			}
		},
		onLoad(op) {
			this.initData();
			this.subData.id = op.id;
			if (op.id) {
				this.getAccountData();
			}
		},
		methods: {
			doSub() {
				postAccount(this.subData).then(res => {
					this.$refs.uToast.show({
						type: 'default',
						message: "操作成功",
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err.info,
						icon: 'none',
						duration: 2000
					})
				})
			},
			del() {
				accountDel({
					id: this.subData.id
				}).then(res => {
					this.$refs.uToast.show({
						type: 'default',
						message: "操作成功",
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err.info,
						icon: 'none',
						duration: 2000
					})
				})
			},
			getAccountData() {
				getAccount({
					id: this.subData.id
				}).then(res => {
					this.subData = res;
				})
			},
			initData() {
				getSearchData().then(res => {
					for (var item of res) {
						if (item.flag == 'PopuPlatform') {
							this.platform = item.data;
						}

						if (item.flag == 'Category') {
							this.category = item.data;
						}

						if (item.flag == 'Status') {
							this.status = item.data;
						}
					}
				})
			}
		}
	}
</script>

<style>
	/deep/ .selected-area.placeholder {
		color: #c0c4cc !important;
		font-size: 15px !important;
	}

	/deep/ .input-value.input-value-border {
		height: 38px !important;
		padding: 6px 9px !important;
	}
</style>
